package com.ikas.ai.server.module.analyse.controller;

import com.ikas.ai.handle.JsonResult;
import com.ikas.ai.server.aop.Pageable;
import com.ikas.ai.server.module.AbstractBean;
import com.ikas.ai.server.module.analyse.model.dto.TrendQueryDTO;
import com.ikas.ai.server.module.analyse.service.DorisTrendAnalysisService;
import com.ikas.ai.server.module.analyse.service.DorisExceptionAnalysisService;
import com.ikas.ai.server.module.analyse.service.TrendAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 执行响应趋势分析
 *
 * @author tang.xuandong
 * @version 1.0.0
 * @date 2023/2/1 10:49
 */
@RestController
@RequestMapping("/analysis/trend")
public class TrendAnalysisController extends AbstractBean {

    @Autowired
    private DorisTrendAnalysisService dorisTrendAnalysisService;

    /**
     * 获取分页数据
     *
     * @param req 查询条件
     * @return Json
     */
    @Pageable(sortType = "desc", sortBy = "id")
    @GetMapping("/page")
    public JsonResult pageQueryTrendAnalysis(TrendQueryDTO req) {
        return JsonResult.ok(dorisTrendAnalysisService.pageQueryTrend(req));
    }

    /**
     * 获取数据(不分页)
     *
     * @param req 查询条件
     * @return Json
     */
    @GetMapping("/list")
    public JsonResult queryTrendAnalysis(TrendQueryDTO req) {
        return JsonResult.ok(dorisTrendAnalysisService.listQueryTrend(req));
    }

    /**
     * 导出
     *
     * @param response HttpServletResponse
     * @param req      TrendQueryDTO
     */
    @ResponseBody
    @GetMapping("/export")
    public void export(HttpServletResponse response, TrendQueryDTO req) {
        dorisTrendAnalysisService.export(response, req);
    }
}
